package com.zxy.controller;

import com.zxy.server.OrderServer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author : zhangxuyuan
 * @Project: springbootrabbitmq
 * @Package com.zxy.controller
 * @date Date : 2021年04月20日 22:45
 */
@CrossOrigin
@RestController
public class IndexController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/create")
    public String create()
    {
        Integer orderId = OrderServer.createOrder();
        rabbitTemplate.convertAndSend("order",orderId);
        return "create";
    }

    @GetMapping("/get")
    public Map<Integer,Integer> get()
    {
        return OrderServer.getOrders();
    }

    @GetMapping("/pay")
    public String pay(Integer orderId)
    {
        OrderServer.payOrder(orderId);
        return "pay";
    }


}
